#include <iostream>

void swap(int* p, int* q)
{
	int tmp = *p;
	*p = *q;
	*q = tmp;
}

void qsort(int* a, int begin, int end)
{
	if (begin >= end) return;

	int left = begin, right = end;
	int keyi = begin;
	int key = a[keyi];

	while (left < right)
	{
		while (left < right && a[right] >= key)
			right--;
		while (left < right && a[left] <= key)
			left++;
		swap(&a[left], &a[right]);
	}

	swap(&a[left], &a[keyi]);
	qsort(a, 0, left - 1);
	qsort(a, left + 1, end);
}

int main()
{
	int a[] = {2,1,3,2,9,7,8,6,4,5,0};
	int n = sizeof(a) / sizeof(a[0]);
	qsort(a, 0, n-1);
	for (auto i : a)
	{
		std::cout << " " << i;
	}
}



